/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.spts.funds.service  
 */
package com.apache.funds.service;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.apache.api.api.ApiService;
import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.exception.ServiceException;
import com.apache.funds.util.Prompt;

/**
 * description:  
 * @author goldocean 创建时间：2014-11-25  
 * 
 */
public class FundsServiceImpl implements ApiService {
	private Map<String, PluginConnector> plugins;
	private Logger log = LoggerFactory.getLogger(getClass());

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.apache.api.api.ApiService#doService(com.apache.api.vo.ParamsVo)  
	 */
	@Override
	public ResultEntity doService(ParamsVo vo) throws ServiceException {
		ResultEntity result = new ResultEntity();
		result.setResult("true");
		if (Validator.isEmpty(plugins.get(vo.getMethodKey()))) {
			result.setMessage(Prompt.NOMETHOD);
		} else {
			try {
				return (ResultEntity) plugins.get(vo.getMethodKey()).execute(vo);
			} catch (Exception e) {
				e.printStackTrace();
				log.error(e.getMessage());
				//throw new ServiceException(Prompt.EXECUTE + "[" + vo.getMethodKey() + "]", e);
				result.setEntity("false");
				result.setMessage(e.getMessage());
			}
		}
		return result;
	}

	public void setPlugins(Map<String, PluginConnector> plugins) {
		this.plugins = plugins;
	}

}
